package com.ruoyi.hr.controller.hr.salaryadmin.salaryinfo;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.hr.domain.Authority;
import com.ruoyi.hr.service.AuthorityService;
import com.ruoyi.hr.service.salaryadmin.salaryinfo.BtSalaryInfoService;
import com.ruoyi.system.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * 拜特薪资信息(所有员工)
 */
@Controller
@RequestMapping("/salaryInfo/btSalaryInfo")
public class BtSalaryInfoController extends BaseController {

    @Autowired
    BtSalaryInfoService btSalaryInfoService;

    @Autowired
    AuthorityService authorityService;

    private String prefix = "hr/salaryadmin/salaryinfo/btsalaryinfo";

    /**
     * 跳转初始化页面
     */
    @GetMapping()
    public String btSalaryInfo() {
        return prefix + "/btSalaryInfo";
    }

    /**
     * 根据pgid拿到所有数据
     *
     * @param map
     * @return
     */
    @RequestMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map map) {
        SysUser user = ShiroUtils.getSysUser();
        List<Authority> authorityList = authorityService.getAuthorityUser(user.getUserId().toString());
        int isAdmin = 0;
        if (authorityList.size() == 1) {
            if (authorityList.get(0).getIsAdmin() != null) {
                isAdmin = 1;
            }
        }
        startPage();
        return getDataTable(btSalaryInfoService.findDataByPgid(map, authorityList, isAdmin));
    }

    @RequestMapping("/bankNumValidationList")
    @ResponseBody
    public TableDataInfo bankNumValidationList(@RequestParam Map map) {
        SysUser user = ShiroUtils.getSysUser();
        List<Authority> authorityList = authorityService.getAuthorityUser(user.getUserId().toString());
        int isAdmin = 0;
        if (authorityList.size() == 1) {
            if (authorityList.get(0).getIsAdmin() != null) {
                isAdmin = 1;
            }
        }
        startPage();
        return getDataTable(btSalaryInfoService.bankNumValidationList(map, authorityList, isAdmin));
    }

    @GetMapping("/bankNumRepeatValidation")
    public String bankNumRepeatValidation() {
        return prefix + "/bankNumRepeatValidation";
    }
}
